package com.example.demo.service.baseContext;

import com.example.demo.common.ThreadUserPojo;
import org.springframework.stereotype.Service;

@Service
public class BaseContextService {
    private static final ThreadLocal<ThreadUserPojo> currentUserId = new ThreadLocal<>();

    public void setUserData(ThreadUserPojo userData) {
        currentUserId.set(userData);
    }

    public ThreadUserPojo getUserData() {
        ThreadUserPojo threadUserPojo = currentUserId.get();
        if (threadUserPojo != null) {
            return threadUserPojo;
        }
        ThreadUserPojo threadUserPojo1 = new ThreadUserPojo();
        setUserData(threadUserPojo1);
        return threadUserPojo1;
    }

    public void setUserToTopAdmin() {
        ThreadUserPojo userData = getUserData();
        userData.setTopAdmin(true);
        setUserData(userData);
    }
}
